<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>更新家庭成员信息</title>
    <link rel="stylesheet" href="../../css/ok/oksub.css">
    <script type="text/javascript" src="../../libs/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form" lay-filter="filter">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="hidden" name="memberid">
                <input type="text" name="name" required lay-verify="required"
                       placeholder="请输入家庭成员姓名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">亲属关系</label>
            <div class="layui-input-block">
                <select name="relation" lay-verify="required">
                    <option value=""></option>
                    <option value="父亲">父亲</option>
                    <option value="母亲">母亲</option>
                    <option value="姐姐">姐姐</option>
                    <option value="哥哥">哥哥</option>
                    <option value="弟弟">弟弟</option>
                    <option value="妹妹">妹妹</option>
                    <option value="其他">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="phonenumber" lay-verify="required|phone|number"
                       placeholder="联系电话"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">住址</label>
            <div class="layui-input-block">
                <input type="text" name="address" lay-verify="required" placeholder="居住地址"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职业</label>
            <div class="layui-input-block">
                <input type="text" name="occupation" lay-verify="required" placeholder="亲属职业"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formfamily">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<!--js逻辑-->
<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script>
    let initData;

    function initForm(data) {
        console.log(data)
        let jsonString = JSON.stringify(data);
        console.log(jsonString);
        initData = JSON.parse(jsonString);
    }

    layui.use(["element", "form", "okLayer", "okUtils"], function () {
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        form.val("filter", initData);
        okLoading.close();
        //
        // form.verify({
        //     birthdayVerify: [/^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))(\s(([01]\d{1})|(2[0123])):([0-5]\d):([0-5]\d))?$/, '日期格式不正确']
        // });
        // 获取enterprise
        var student = JSON.parse(window.sessionStorage.getItem("student"));

        form.on("submit(formfamily)", function (data) {
            var family = new FamilyMember(data.field.memberid, data.field.name, data.field.relation, data.field.phonenumber, data.field.address, data.field.occupation, student);

            okUtils.ajax("/ygssecs/upfamilymember", "post", {familyjson: JSON.stringify(family)}, true).done(function (response) {
                if (response.code == 200) {
                    okLayer.greenTickMsg(response.msg, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    });
                } else {
                    okLayer.yellowSighMsg(response.msg);
                }
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    })
</script>
</body>
</html>